/*
 * Copyright (C) 2012 Tomas Shestakov. <http://code.google.com/p/jmmo/>
 */

package jmmo.engine.multifacetedactor

import akka.actor.{Actor, ActorRef, ActorContext}
import jmmo.engine.property.Property

/**
 *
 * @author Tomas Shestakov
 */
trait ActorRole {

  type OwnerActor <: MultifacetedActor

  def id: Any

  implicit var context: ActorContext = _

  var actor: OwnerActor = _

  implicit def self: ActorRef = context.self

  def sender: ActorRef = context.sender

  def properties: scala.collection.Map[Any, Property[_]] = Map.empty

  def iface: Option[AnyRef] = None

  def receive: OwnerActor#Receive

  /**
   * If you not wanna to role to be available immediately you must override this method with empty one.
   */
  def preStart() {
    //Each role must report to manager when it will be ready
    actor.sendInside(RoleAvailable(this))
  }

  def postStop() {}

  def preRestart(reason: Throwable, message: Option[Any]) {}

  def postRestart(reason: Throwable) {}

}
